- Notifications
You must be signed in to change notification settings - Fork 251
/
Copy pathIris_Data.py
48 lines (30 loc) · 908 Bytes
/
Iris_Data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#-*- coding:utf-8 -*-
# &Author AnFany
importpandasaspd
data=pd.read_csv(r'C:\Users\GWT9\Desktop\iris.csv')
# y值Softmax
ydata=data['Species'].values
# x值
xdata=data.iloc[:, 1:5].values
# 数据处理
importnumpyasnp
# x数据标准化
handle_x_data= (xdata-np.mean(xdata, axis=0)) /np.std(xdata, axis=0)
# y数据独热化
ydata=pd.get_dummies(data['Species']).values
# 因为数据中类别比较集中,不易于训练,因此打乱数据
# 首先将x数据和y数据合在一起
xydata=np.hstack((handle_x_data, ydata))
# 打乱顺序
np.random.shuffle(xydata)
# 分离数据
X_DATA=xydata[:, :4]
Y_DATA=xydata[:, 4:]
Data= [X_DATA, Y_DATA]
# 数据结构
# X_DATA.shape = (样本数, 特征数)
# Y_DATA.shape = (样本数, 类别数)
# 类别
# setosa [1,0,0]
# versicolor [0,1,0]
# virginica [0,0,1]